package ernie.server;

import java.util.HashMap;

import ernie.pages.DummyPage;
import ernie.pages.Page;

/**
 * @author Filip Lindqvist <buggfille@gmail.com>
 * @created 6:43:00 PM - Nov 11, 2011
 */
public class PageDispatcher {
    private final HashMap<String, Page> list;

    public PageDispatcher() {
        list = new HashMap<String, Page>();
        Page dummy = new DummyPage();
        addPage(dummy);
    }

    public boolean isPage(String name) {
        return list.get(name) != null;
    }

    public String getPage(String name) throws NoSuchPageException {
        Page p = list.get(name);
        if (p != null) {
            return p.getContent();
        } else {
            throw new NoSuchPageException();
        }
    }

    public void addPage(Page p) {
        list.put(p.file(), p);
    }
}
